package com.yonyou.brigade.third_parties.ctrip.groupmembers.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.dao.CtripGroupMapper;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.pojo.CtripGroup;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.pojo.CtripGroupExt;
import com.yonyou.brigade.third_parties.ctrip.groupmembers.service.ICtripGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jiangzhf@yonyou.com
 * @since 2018-05-03
 */
@Service
public class CtripGroupServiceImpl extends ServiceImpl<CtripGroupMapper, CtripGroup> implements ICtripGroupService {

    @Autowired
    private CtripGroupMapper ctripGroupMapper;

    @Override
    public String invokeMethod(String methodName, Map param) {
        switch (methodName){
            case "findGroups":return JSON.toJSONString(findGroups(param.get("tenantid").toString()));
            case "insert":
                CtripGroup ctripGroup = JSON.parseObject(JSON.toJSONString(param.get("ctripGroup")) , CtripGroup.class);
                ctripGroup.setTenantid(param.get("tenantid").toString());
                this.insert(ctripGroup); break;
            case "update":
                CtripGroup ctripGroup1 = JSON.parseObject(JSON.toJSONString(param.get("ctripGroup")) , CtripGroup.class);
                ctripGroup1.setTenantid(param.get("tenantid").toString());
                this.updateById(ctripGroup1);break;
            case "group":
                return JSON.toJSONString(this.selectById((int)param.get("id")));
            case "delgroup":
                this.deleteById((Integer)param.get("id"));break;
        }
        return null;
    }

    public List<CtripGroupExt> findGroups(String tenantid) {
        return  ctripGroupMapper.findGroups(tenantid);
    }
}
